<?php

/**
 * @author lzp300
 * @copyright 2015-03-26
 */
class newxHotel extends actionAbstract{
	//构造函数
	function __construct() {
		parent::__construct ();
		set_time_limit ( 0 );
	}
	
	function SignUtil($serviceName="1",$accountKey="qingmangguokey",$version="1.1.0",$accountID="qingmangguo"){
        $reqTime=date('Y-m-d',time());
        
        $resuoce=array();
        $resuoce['state']=0;
        $resuoce['string']="";
        
        $originalArray=array();
        $originalArray['Version']=$version;
        $originalArray['AccountID']=$accountID;
        $originalArray['ReqTime']=$reqTime;
        if($serviceName){
            $originalArray['ServiceName']=$serviceName;
            ksort($originalArray);
            $sortedArray="";
            foreach($originalArray as $k=>$v){
                $sortedArray.=$k.'='.$v.'&';
            }
            $sortedArray=trim($sortedArray,'&');
            $keywords=md5($sortedArray.$accountKey);
            $resuoce['state']=1;
            $resuoce['string']['version']=$version;
            $resuoce['string']['accountId']=$accountID;
            $resuoce['string']['serviceName']=$serviceName;
            $resuoce['string']['sign']=$keywords;
            $resuoce['string']['reqTime']=$reqTime;
            //var_dump($resuoce);
        }else{
            $resuoce['string']='接口方法名错误！';
        }
        return $resuoce;
    }
    
    /**
     * curl 传输      //测试：120.24.75.164:8999---正式：120.24.166.230:8999
     */
    function curl($post_data,$url="http://120.24.166.230:8999/PmsInterfaceConnections/PmsDataInterFace/getPmsMethod"){
        $ch = curl_init();
        //print_r($ch);
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_TIMEOUT,60);
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
        $return = curl_exec ( $ch );
        
		$logs="调用地址：".$url."\r\n接收数据：".$return."\r\n发送数据：".$post_data;
        $this->setLogs($logs,"/data/Logs/hotel/");
		
        curl_close ( $ch );
        $return=json_decode($return,true);
        if($return){
            $body=isset($return['body'])?$return['body']:'';
            $head=isset($return['head'])?$return['head']:'';
            if($head&&is_array($head)&&$head['status']==0&&$head['responseCode']==0000){
				return $body;
			}else{
				return "数据错误，请联系技术人员！";
			}
        }
		return "获取内容失败！";
    }
    
    /**
     * 公共调用
     */
    function thall($actionName,$body){
        $resuoce=$this->SignUtil($actionName);
        if($resuoce['state']==1){
            $post_data=json_encode(array("head"=>$resuoce['string'],"body"=>$body));
            $contArray=$this->curl($post_data);
            return $contArray;
        }else{
            return $resuoce['string'];
        }
    }
	
	//酒店 数组 字符串
	function nowHotel(){
		$this->loadModel('qm','hotel');
		
		$sql="select hid from qm_hotel where `name`!='' and osiiCityID>0 and osiiCountyID>0 and osiiProvinceID>0 and id>3072";//>3072
		$re=$this->qm->hotelModel->fetchAll($sql);
		
		$in="";//酒店字符串
		foreach($re as $k=>$v){$in.="'".$v['hid']."',";}
		$in=trim($in,",");
		
		return $in;
	}
	
	//渠道
	function allChanne(){
		$this->loadModel('qm','channels');
		$sourceId="";
		$ca=$this->qm->channelsModel->fetchAll("select osiiid from qm_channels where status=1");
		if($ca){
			foreach($ca as $k=>$v){
				$sourceId.=','.$v['osiiid'];
			}
			$sourceId=trim($sourceId,',');
		}
		return $sourceId;
	}
	
	//酒店添加、修改  发送 OSII
    function hotels(){
		$this->loadModel('qm','hotel');
		$hid=isset($_POST['hid'])?(int)($_POST['hid']):0;
		if($hid){
			$re=$this->qm->hotelModel->fetchRow("select * from qm_hotel where hid=$hid");
			if($re){
				$body[0]['hotelCode']=$re['hid'];               		$body[0]['hotelName']=$re['name'];
				$body[0]['hotelEnName']="";			           			$body[0]['hotelDescription']=$re['intro'];
				$body[0]['star']=$re['tjgradenum'];						$body[0]['provinceCode']=$re['osiiProvinceID'];
				$body[0]['provinceName']=$re['osiiProvinceName'];		$body[0]['cityCode']=$re['osiiCityID'];
				$body[0]['cityName']=$re['osiiCityName'];				$body[0]['countyCode']=$re['osiiCountyID'];
				$body[0]['countyName']=$re['osiiCountyName'];			$body[0]['brief']="";
				$body[0]['openYear']="2000-01-01";						$body[0]['roomQuantity']=0;
				$body[0]['telephone']=!empty($re['tell'])?$re['tell']:'';	$body[0]['diyBreakfast']=0;
				$body[0]['chineseBreakfast']=0;							$body[0]['westBreakfast']=0;
				$body[0]['fax']="";										$body[0]['address']=$re['address'];
				$arr=$this->thall("GetHotelInfo",$body);
				if($arr&&$arr=='{}'){exit(json_encode(array('state'=>1,'html'=>"成功推送 1 条！")));}
			}
		}else{
			$in=$this->nowHotel();
			$count=$this->qm->hotelModel->fetchRow("select count(hid) as thcount from qm_hotel where hid in (".$in.")");
			$count=$count['thcount'];
			if($count<=10){
				$sql="select hid,`name`,address,osiiCityID,osiiCityName,osiiCountyID,osiiCountyName,osiiProvinceID,osiiProvinceName,tjgradenum,intro,tell from qm_hotel";
				$sql.=" where hid in (".$in.")";
				$re=$this->qm->hotelModel->fetchAll($sql);
				if($re){
					foreach($re as $k=>$v){
						$body[$k]['hotelCode']=$v['hid'];               		$body[$k]['hotelName']=$v['name'];
						$body[$k]['hotelEnName']="";			           		$body[$k]['hotelDescription']=($v['intro']&&$v['intro']!='Array'?$v['intro']:'');
						$body[$k]['star']=$v['tjgradenum'];						$body[$k]['provinceCode']=$v['osiiProvinceID'];
						$body[$k]['provinceName']=$v['osiiProvinceName'];		$body[$k]['cityCode']=$v['osiiCityID'];
						$body[$k]['cityName']=$v['osiiCityName'];				$body[$k]['countyCode']=$v['osiiCountyID'];
						$body[$k]['countyName']=$v['osiiCountyName'];			$body[$k]['brief']="";
						$body[$k]['openYear']="2000-01-01";						$body[$k]['roomQuantity']=0;
						$body[$k]['telephone']=!empty($v['tell'])?$v['tell']:'';	$body[$k]['diyBreakfast']=0;
						$body[$k]['chineseBreakfast']=0;						$body[$k]['westBreakfast']=0;
						$body[$k]['fax']="";									$body[$k]['address']=$v['address'];
					}
					$arr=$this->thall("GetHotelInfo",$body);
					if($arr&&$arr=='{}'){exit(json_encode(array('state'=>1,'html'=>"成功推送 ".$count." 条！")));}
				}
			}else{
				$page=ceil( $count / 10 );$j=0;
				for($i=0;$i<$page;$i++){
					$sql="select hid,`name`,address,osiiCityID,osiiCityName,osiiCountyID,osiiCountyName,osiiProvinceID,osiiProvinceName,tjgradenum,intro,tell from qm_hotel";
					$sql.=" where hid in (".$in.") limit ".($i*10).",10";
					$re=$this->qm->hotelModel->fetchAll($sql);
					if($re){
						foreach($re as $k=>$v){
							$body[$k]['hotelCode']=$v['hid'];               		$body[$k]['hotelName']=$v['name'];
							$body[$k]['hotelEnName']="";			           		$body[$k]['hotelDescription']=($v['intro']&&$v['intro']!='Array'?$v['intro']:'');
							$body[$k]['star']=$v['tjgradenum'];						$body[$k]['provinceCode']=$v['osiiProvinceID'];
							$body[$k]['provinceName']=$v['osiiProvinceName'];		$body[$k]['cityCode']=$v['osiiCityID'];
							$body[$k]['cityName']=$v['osiiCityName'];				$body[$k]['countyCode']=$v['osiiCountyID'];
							$body[$k]['countyName']=$v['osiiCountyName'];			$body[$k]['brief']="";
							$body[$k]['openYear']="2000-01-01";						$body[$k]['roomQuantity']=0;
							$body[$k]['telephone']=!empty($v['tell'])?$v['tell']:'';	$body[$k]['diyBreakfast']=0;
							$body[$k]['chineseBreakfast']=0;						$body[$k]['westBreakfast']=0;
							$body[$k]['fax']="";									$body[$k]['address']=$v['address'];
						}
						$arr=$this->thall("GetHotelInfo",$body);
						if($arr&&$arr=='{}'){$j+=count($re);}
					}
				}
				if($j>0){exit(json_encode(array('state'=>1,'html'=>"成功推送 ".$j." 条！")));}
			}
		}
        exit(json_encode(array('state'=>0,'html'=>"推送失败！")));
    }
    
    //房型添加、修改  发送OSII
    function rooms(){
		$this->loadModel('qm','room');
		$rid=isset($_POST['rid'])?(int)($_POST['rid']):0;
		if($rid){
			$re=$this->qm->roomModel->fetchRow("select * from qm_room where rid=$rid");
			if($re){
				$body[0]['hotelCode'] = $re['hid'];
				$body[0]['roomTypeCode'] = $re['rid'];
				$body[0]['roomName'] = $re['name'];
				$body[0]['areaRange'] = "0.00";
				$body[0]['floorRange'] = "0";
				$body[0]['roomDesc'] = "";
				$body[0]['person'] = $re['maxNum'];
				$body[0]['addBed'] = 0;
				$body[0]['addBedFee'] = 0;
				$body[0]['roomQuantity'] = 0;
				$body[0]['currency'] = "RMB";
				$body[0]['noSmoking'] = 0;
				$body[0]['window'] = 0;
				$body[0]['children'] = 0;
				$body[0]['hasBroadNet'] = "";
				$body[0]['hasWirelessBroadnet'] = "";
				$body[0]['wiredBroadnetRoom'] = 0;
				$body[0]['wirelessBroadnetRoom'] = 0;
				$body[0]['bedTypeID'] = 0;
				$body[0]['bedTypeName'] = "其它";
				$arr=$this->thall("GetRoomTypeInfo",$body);
				if($arr&&$arr=='{}'){exit(json_encode(array('state'=>1,'html'=>"成功推送 1 条！")));}
			}
		}else{
			$in=$this->nowHotel();
			$count=$this->qm->roomModel->fetchRow("select count(rid) as thcount from qm_room where hid in(".$in.")");
			$count=$count['thcount'];
			if($count<=10){
				$re=$this->qm->roomModel->fetchAll("select hid,rid,name,maxNum from qm_room where hid in(".$in.")");
				if($re){
					foreach($re as $k=>$v){
						$body[$k]['hotelCode'] = $v['hid'];
						$body[$k]['roomTypeCode'] = $v['rid'];
						$body[$k]['roomName'] = $v['name'];
						$body[$k]['areaRange'] = "0.00";
						$body[$k]['floorRange'] = "0";
						$body[$k]['roomDesc'] = "";
						$body[$k]['person'] = $v['maxNum'];
						$body[$k]['addBed'] = 0;
						$body[$k]['addBedFee'] = 0;
						$body[$k]['roomQuantity'] = 0;
						$body[$k]['currency'] = "RMB";
						$body[$k]['noSmoking'] = 0;
						$body[$k]['window'] = 0;
						$body[$k]['children'] = 0;
						$body[$k]['hasBroadNet'] = "";
						$body[$k]['hasWirelessBroadnet'] = "";
						$body[$k]['wiredBroadnetRoom'] = 0;
						$body[$k]['wirelessBroadnetRoom'] = 0;
						$body[$k]['bedTypeID'] = 0;
						$body[$k]['bedTypeName'] = "其它";
					}
					$arr=$this->thall("GetRoomTypeInfo",$body);
					if($arr&&$arr=='{}'){exit(json_encode(array('state'=>1,'html'=>"成功推送 ".$count." 条！")));}
				}
			}else{
				$page=ceil( $count / 10 );$j=0;
				for($i=0;$i<$page;$i++){
					$re=$this->qm->roomModel->fetchAll("select hid,rid,name,maxNum from qm_room where hid in(".$in.") limit ".($i*10).",10");
					if($re){
						foreach($re as $k=>$v){
							$body[$k]['hotelCode'] = $v['hid'];
							$body[$k]['roomTypeCode'] = $v['rid'];
							$body[$k]['roomName'] = $v['name'];
							$body[$k]['areaRange'] = "0.00";
							$body[$k]['floorRange'] = "0";
							$body[$k]['roomDesc'] = "";
							$body[$k]['person'] = $v['maxNum'];
							$body[$k]['addBed'] = 0;
							$body[$k]['addBedFee'] = 0;
							$body[$k]['roomQuantity'] = 0;
							$body[$k]['currency'] = "RMB";
							$body[$k]['noSmoking'] = 0;
							$body[$k]['window'] = 0;
							$body[$k]['children'] = 0;
							$body[$k]['hasBroadNet'] = "";
							$body[$k]['hasWirelessBroadnet'] = "";
							$body[$k]['wiredBroadnetRoom'] = 0;
							$body[$k]['wirelessBroadnetRoom'] = 0;
							$body[$k]['bedTypeID'] = 0;
							$body[$k]['bedTypeName'] = "其它";
						}
						$arr=$this->thall("GetRoomTypeInfo",$body);
						if($arr&&$arr=='{}'){$j+=count($re);}
					}
				}
				if($j>0){exit(json_encode(array('state'=>1,'html'=>"成功推送 ".$j." 条！")));}
			}
		}
		exit(json_encode(array('state'=>0,'html'=>"推送失败！")));
    }
    
    //图片添加、修改 发送OSII
    function imgs(){
		$this->loadModel('qm','image');
		$kid=isset($_POST['kid'])?(int)($_POST['kid']):0;
		if($kid){
			$re=$this->qm->imageModel->fetchRow("select * from qm_image where id=$kid");
			if($re){
				$body[0]['hotelCode']=$re['hid'];
				$body[0]['picName']=$re['title'];
				$body[0]['picUrl']=$re['url'];
				$body[0]['licensedDownload']=0;
				$arr=$this->thall("GetHotelImageInfo",$body);
				if($arr&&$arr=='{}'){exit(json_encode(array('state'=>1,'html'=>"成功推送 1 条！")));}
			}
		}else{
			$in=$this->nowHotel();
			
			$count=$this->qm->imageModel->fetchRow("select count(id) as thcount from qm_image where hid in (".$in.")");
			$count=$count['thcount'];
			if($count<=10){
				$re=$this->qm->imageModel->fetchAll("select * from qm_image where hid in (".$in.")");
				if($re){
					foreach($re as $k=>$v){
						$body[$k]['hotelCode']=$v['hid'];
						$body[$k]['picName']=$v['title'];
						$body[$k]['picUrl']=$v['url'];
						$body[$k]['licensedDownload']=0;
					}
					$arr=$this->thall("GetHotelImageInfo",$body);
					if($arr&&$arr=='{}'){exit(json_encode(array('state'=>1,'html'=>"成功推送 ".$count." 条！")));}
				}
			}else{
				$page=ceil( $count / 10 );$j=0;
				for($i=0;$i<$page;$i++){
					$re=$this->qm->imageModel->fetchAll("select * from qm_image where hid in (".$in.") limit ".($i*10).",10");
					if($re){
						foreach($re as $k=>$v){
							$body[$k]['hotelCode']=$v['hid'];
							$body[$k]['picName']=$v['title'];
							$body[$k]['picUrl']=$v['url'];
							$body[$k]['licensedDownload']=0;
						}
						$arr=$this->thall("GetHotelImageInfo",$body);
						if($arr&&$arr=='{}'){$j+=count($re);}
					}
				}
				if($j>0){exit(json_encode(array('state'=>1,'html'=>"成功推送 ".$j." 条！")));}
			}
		}
		exit(json_encode(array('state'=>0,'html'=>"推送失败！")));
    }
    
    //房型价格 添加、修改 发送OSII
    function typePrice(){
		$this->loadModel('qm','roombatch');
		$this->loadModel('qm','channels');
		$Thotel=isset($_POST['Thotel'])?(int)($_POST['Thotel']):0;
		$Thtype=isset($_POST['Thtype'])?(int)($_POST['Thtype']):0;
		$Tchannels=isset($_POST['Tchannels'])?(int)($_POST['Tchannels']):0;
		$start=isset($_POST['start'])?$_POST['start']:date('Y-m-d',time()+24*3600);
		$end=isset($_POST['end'])?$_POST['end']:'';
		
		$Qchannels=$this->allChanne();
		$in=$this->nowHotel();
		
		$sql="select count(id) as thcount from qm_roombatch where hid in (".$in.")";
		$where="";
		if($Thotel){$where.=" and hid=$Thotel";}
		if($Thtype){$where.=" and rid=$Thtype";}
		if($start){$where.=" and date>='".$start."'";}
		if($end){$where.=" and date<='".$end."'";}
		$count=$this->qm->roombatchModel->fetchRow($sql.$where);
		$count=$count['thcount'];
		if(!$count){exit(json_encode(array('state'=>0,'html'=>"没有可用房价推送！")));}
		if($count<=10){
			$re=$this->qm->roombatchModel->fetchAll("select * from qm_roombatch where hid in (".$in.")".$where);
			if($re){
				foreach($re as $k=>$v){
					$body = array('setRoomPriceItems' => array());
					$body['setRoomPriceItems'][0]['priceInfos'] = array();
					$body['setRoomPriceItems'][0]['hotelId'] = $v['hid'];
					$body['setRoomPriceItems'][0]['sourceId'] = $Qchannels;
					$body['setRoomPriceItems'][0]['roomId'] = $v['rid'];
					$body['setRoomPriceItems'][0]['startDate'] = $v['date'].'T00:00:00';
					$body['setRoomPriceItems'][0]['endDate'] = $v['date'].'T00:00:00';
					$body['setRoomPriceItems'][0]['currency'] = "CNY";
					$body['setRoomPriceItems'][0]['currency'] = "CNY";
					$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'] = array();
					$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['amountBeforeTaxFee'] = $v['price'];
					$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['amountAfterTaxFee'] = $v['price'];
					$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['costAmountBeforeTaxFee'] = $v['price'];
					$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['costAmountAfterTaxFee'] = $v['price'];
					$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['day'] = 0;
					$body['setRoomPriceItems'][0]['priceInfos'][0]['stays'] = 0;
					$body['setRoomPriceItems'][0]['priceInfos'][0]['blanceType'] = "PP";
					$body['setRoomPriceItems'][0]['priceInfos'][0]['priceType'] = "Cost";
					$breakfast=0;
					if($v['breakfast']=="1份"||$v['breakfast']=="含早餐"){
						$breakfast=1;
					}elseif($v['breakfast']=="2份"){
						$breakfast=2;
					}
					$body['setRoomPriceItems'][0]['priceInfos'][0]['breakfast'] = $breakfast;
					$body['setRoomPriceItems'][0]['priceInfos'][0]['isCancel'] = 0;
					$arr=$this->thall("SetRoomPrice",$body);
				}
			}
		}else{
			$page=ceil( $count / 10 );
			for($i=0;$i<$page;$i++){
				$re=$this->qm->roombatchModel->fetchAll("select * from qm_roombatch where hid in (".$in.")".$where." limit ".($i*10).",10");
				if($re){
					foreach($re as $k=>$v){
						$body = array('setRoomPriceItems' => array());
						$body['setRoomPriceItems'][0]['priceInfos'] = array();
						$body['setRoomPriceItems'][0]['hotelId'] = $v['hid'];
						$body['setRoomPriceItems'][0]['sourceId'] = $Qchannels;
						$body['setRoomPriceItems'][0]['roomId'] = $v['rid'];
						$body['setRoomPriceItems'][0]['startDate'] = $v['date'].'T00:00:00';
						$body['setRoomPriceItems'][0]['endDate'] = $v['date'].'T00:00:00';
						$body['setRoomPriceItems'][0]['currency'] = "CNY";
						$body['setRoomPriceItems'][0]['currency'] = "CNY";
						$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'] = array();
						$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['amountBeforeTaxFee'] = $v['price'];
						$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['amountAfterTaxFee'] = $v['price'];
						$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['costAmountBeforeTaxFee'] = $v['price'];
						$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['costAmountAfterTaxFee'] = $v['price'];
						$body['setRoomPriceItems'][0]['priceInfos'][0]['prices'][0]['day'] = 0;
						$body['setRoomPriceItems'][0]['priceInfos'][0]['stays'] = 0;
						$body['setRoomPriceItems'][0]['priceInfos'][0]['blanceType'] = "PP";
						$body['setRoomPriceItems'][0]['priceInfos'][0]['priceType'] = "Cost";
						$breakfast=0;
						if($v['breakfast']=="1份"||$v['breakfast']=="含早餐"){
							$breakfast=1;
						}elseif($v['breakfast']=="2份"){
							$breakfast=2;
						}
						$body['setRoomPriceItems'][0]['priceInfos'][0]['breakfast'] = $breakfast;
						$body['setRoomPriceItems'][0]['priceInfos'][0]['isCancel'] = 0;
						$arr=$this->thall("SetRoomPrice",$body);
					}
				}
			}
		}
		exit(json_encode(array('state'=>1,'html'=>"房价操作成功，共".$count."条，如有问题请查看详细日志！")));
    }
	
    //设置房态 添加、修改  发送OSII
    function roomstatus(){
		$this->loadModel('qm','roombatch');
		$this->loadModel('qm','channels');
		$Thotel=isset($_POST['Thotel'])?(int)($_POST['Thotel']):0;
		$Thtype=isset($_POST['Thtype'])?(int)($_POST['Thtype']):0;
		$Tchannels=isset($_POST['Tchannels'])?(int)($_POST['Tchannels']):0;
		$start=isset($_POST['start'])?$_POST['start']:date('Y-m-d',time()+24*3600);
		$end=isset($_POST['end'])?$_POST['end']:'';
		
		$body['sourceId']=$this->allChanne();$body['editer']='qmg';
		$in=$this->nowHotel();
		
		$sql="select count(id) as thcount from qm_roombatch where hid in (".$in.")";
		$where="";
		if($Thotel){$where.=" and hid=$Thotel";}
		if($Thtype){$where.=" and rid=$Thtype";}
		if($start){$where.=" and date>='".$start."'";}
		if($end){$where.=" and date<='".$end."'";}
		$count=$this->qm->roombatchModel->fetchRow($sql.$where);
		$count=$count['thcount'];
		if(!$count){exit(json_encode(array('state'=>0,'html'=>"没有可用房态推送！")));}
		if($count<=10){
			$re=$this->qm->roombatchModel->fetchAll("select * from qm_roombatch where hid in (".$in.")".$where);
			if($re){
				$body['roomInfoList']=array();
				foreach($re as $k=>$v){
					$body['hotelCode']=$v['hid'];
					$body['startDate']=$v['date'];
					$body['endDate']=$v['date'];
					$body['roomID']=$v['rid'];
					$body['roomInfoList'][0]['fl']=$v['maxNum'];
					$body['roomInfoList'][0]['setToDate']=$v['date'];
					$body['roomInfoList'][0]['changeDefault']='T';
					$body['roomInfoList'][0]['holdDeadline']='9999';
					$body['roomInfoList'][0]['note']='';
					$body['roomInfoList'][0]['reserveTime']='0';
					$body['roomInfoList'][0]['roomstatus']=$v['roomStatus']==1?'G':'N';
					$body['roomInfoList'][0]['roomsInv']='0';
					$body['roomInfoList'][0]['guarantee']='';
					$body['roomInfoList'][0]['guaranteeLCT']=4;
					$body['roomInfoList'][0]['prepayLCT']=23988;
					$body['roomInfoList'][0]['allNeedGuarantee']='F';
					$body['roomInfoList'][0]['lateReserveTime']=0;
					$body['roomInfoList'][0]['deductType']='C';
					$body['roomInfoList'][0]['blanceType']='PP';
					$body['roomInfoList'][0]['restorable']='F';
					$body['roomInfoList'][0]['checkType']='C';
					$body['roomInfoList'][0]['userLimited']='9999';
					$arr=$this->thall("SetRoomInfo",$body);
				}
			}
		}else{
			$page=ceil( $count / 10 );
			for($i=0;$i<$page;$i++){
				$re=$this->qm->roombatchModel->fetchAll("select * from qm_roombatch where hid in (".$in.")".$where." limit ".($i*10).",10");
				if($re){
					foreach($re as $k=>$v){
						$body['hotelCode']=$v['hid'];
						$body['startDate']=$v['date'];
						$body['endDate']=$v['date'];
						$body['roomID']=$v['rid'];
						$body['roomInfoList'][0]['fl']=$v['maxNum'];
						$body['roomInfoList'][0]['setToDate']=$v['date'];
						$body['roomInfoList'][0]['changeDefault']='T';
						$body['roomInfoList'][0]['holdDeadline']='9999';
						$body['roomInfoList'][0]['note']='';
						$body['roomInfoList'][0]['reserveTime']='0';
						$body['roomInfoList'][0]['roomstatus']=$v['roomStatus']==1?'G':'N';
						$body['roomInfoList'][0]['roomsInv']='0';
						$body['roomInfoList'][0]['guarantee']='';
						$body['roomInfoList'][0]['guaranteeLCT']=4;
						$body['roomInfoList'][0]['prepayLCT']=23988;
						$body['roomInfoList'][0]['allNeedGuarantee']='F';
						$body['roomInfoList'][0]['lateReserveTime']=0;
						$body['roomInfoList'][0]['deductType']='C';
						$body['roomInfoList'][0]['blanceType']='PP';
						$body['roomInfoList'][0]['restorable']='F';
						$body['roomInfoList'][0]['checkType']='C';
						$body['roomInfoList'][0]['userLimited']='9999';
						$arr=$this->thall("SetRoomInfo",$body);
					}
				}
			}
		}
		exit(json_encode(array('state'=>1,'html'=>"房态操作成功，共".$count."条，如有问题请查看详细日志！")));
    }
	
	//满房推送
	function tdroomstaus(){
		$this->loadModel('qm','roombatch');
		$this->loadModel('qm','channels');
		
		$type=isset($_POST['type'])?$_POST['type']:1;
		if($type==2){$where=" and date='".date('Y-m-d',time()+24*3600)."'";}else{$where=" and date='".date('Y-m-d',time())."'";}
		
		$body['sourceId']=$this->allChanne();$body['editer']='qmg';
		$in=$this->nowHotel();
		
		$count=$this->qm->roombatchModel->fetchRow("select count(id) as thcount from qm_roombatch where hid in (".$in.")".$where);
		$count=$count['thcount'];
		if(!$count){exit(json_encode(array('state'=>0,'html'=>"没有可用房态推送！")));}
		if($count<=10){
			$re=$this->qm->roombatchModel->fetchAll("select * from qm_roombatch where hid in (".$in.")".$where);
			if($re){
				$body['roomInfoList']=array();
				foreach($re as $k=>$v){
					$body['hotelCode']=$v['hid'];
					$body['startDate']=$v['date'];
					$body['endDate']=$v['date'];
					$body['roomID']=$v['rid'];
					$body['roomInfoList'][0]['fl']=$v['maxNum'];
					$body['roomInfoList'][0]['setToDate']=$v['date'];
					$body['roomInfoList'][0]['changeDefault']='T';
					$body['roomInfoList'][0]['holdDeadline']='9999';
					$body['roomInfoList'][0]['note']='';
					$body['roomInfoList'][0]['reserveTime']='0';
					$body['roomInfoList'][0]['roomstatus']='N';
					$body['roomInfoList'][0]['roomsInv']='0';
					$body['roomInfoList'][0]['guarantee']='';
					$body['roomInfoList'][0]['guaranteeLCT']=4;
					$body['roomInfoList'][0]['prepayLCT']=23988;
					$body['roomInfoList'][0]['allNeedGuarantee']='F';
					$body['roomInfoList'][0]['lateReserveTime']=0;
					$body['roomInfoList'][0]['deductType']='C';
					$body['roomInfoList'][0]['blanceType']='PP';
					$body['roomInfoList'][0]['restorable']='F';
					$body['roomInfoList'][0]['checkType']='C';
					$body['roomInfoList'][0]['userLimited']='9999';
					$arr=$this->thall("SetRoomInfo",$body);
				}
			}
		}else{
			$page=ceil( $count / 10 );
			for($i=0;$i<$page;$i++){
				$re=$this->qm->roombatchModel->fetchAll("select * from qm_roombatch where hid in (".$in.")".$where." limit ".($i*10).",10");
				if($re){
					foreach($re as $k=>$v){
						$body['hotelCode']=$v['hid'];
						$body['startDate']=$v['date'];
						$body['endDate']=$v['date'];
						$body['roomID']=$v['rid'];
						$body['roomInfoList'][0]['fl']=$v['maxNum'];
						$body['roomInfoList'][0]['setToDate']=$v['date'];
						$body['roomInfoList'][0]['changeDefault']='T';
						$body['roomInfoList'][0]['holdDeadline']='9999';
						$body['roomInfoList'][0]['note']='';
						$body['roomInfoList'][0]['reserveTime']='0';
						$body['roomInfoList'][0]['roomstatus']='N';
						$body['roomInfoList'][0]['roomsInv']='0';
						$body['roomInfoList'][0]['guarantee']='';
						$body['roomInfoList'][0]['guaranteeLCT']=4;
						$body['roomInfoList'][0]['prepayLCT']=23988;
						$body['roomInfoList'][0]['allNeedGuarantee']='F';
						$body['roomInfoList'][0]['lateReserveTime']=0;
						$body['roomInfoList'][0]['deductType']='C';
						$body['roomInfoList'][0]['blanceType']='PP';
						$body['roomInfoList'][0]['restorable']='F';
						$body['roomInfoList'][0]['checkType']='C';
						$body['roomInfoList'][0]['userLimited']='9999';
						$arr=$this->thall("SetRoomInfo",$body);
					}
				}
			}
		}
		exit(json_encode(array('state'=>1,'html'=>"房态操作成功，共".$count."条，如有问题请查看详细日志！")));
	}
	
    //获取房型对照表
    function roomTypeInfo($body){
        $arr=$this->thall("GetContrastRoomTypeInfo",$body);
        return $arr;
    }
    
    //设施、设备  添加、修改 发送OSII
    function devices($body){
        $arr=$this->thall("GetHotelFacilityInfo",$body);
        return $arr;
    }

    //设置酒店状态
    function setHotelStatus($body){
        $arr=$this->thall("SetHotelStatus",$body);
        return $arr;
    }
    
    //渠道开关
    function SetDistributionChannel($body){
        $arr=$this->thall_qudao("SetDistributionChannel",$body);
        return $arr;
    }
    
    /**
     * 对订单状态进行操作(去哪儿)
     * @param type $body
     * @return type
     */
    function  OptOrder($body){
        $arr=$this->thall("OptOrder",$body);
        return $arr;
    }
    
    /**
     * 对订单状态进行操作(携程)
     * @param type $body
     * @return type
     */
    function DomesticPushOrderStatus($body){
        $arr=$this->thall("DomesticPushOrderStatus",$body);
        return $arr;
    }
}